package topt_12z.logging;

import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JTextArea;

import topt_12z.gui.MainFrame;

public class IO {
	private Logger log = null;
	private MainFrame frame = null;

	private static IO instance = null;

	private IO(){
		
	}
	
	public void init() throws Exception{
		// private constructor
		log = Logger.getLogger("GeneralLogger");
		log.setUseParentHandlers(false);
		log.setLevel(Level.FINEST);

		Handler fh1 = new FileHandler("TOPT_12Z.log");
		fh1.setFormatter(new LogFormatter());
		fh1.setLevel(Level.ALL);
		
		Handler ta1 = new TextAreaHandler(frame);
		ta1.setFormatter(new LogFormatter());
		ta1.setLevel(Level.INFO);

		log.addHandler(fh1);
		log.addHandler(ta1);
	}

	public static synchronized IO getInstance() throws Exception {
		if (instance == null) {
			instance = new IO();
		}
		return instance;
	}

	public Logger getLogger() {
		return log;
	}

	public void reset() {
		instance = null;
		log = null;
	}

	public void setTextArea(MainFrame mainFrame) {
		frame = mainFrame;
		
	}


}
